package com.laotang.第_10_章_二叉搜索树.力扣_530_二叉搜索树的最小绝对差;

import com.laotang.第_10_章_二叉搜索树.TreeNode;

public class _530_minimum_absolute_difference_in_bst {
    TreeNode prev = null;
    int res = Integer.MAX_VALUE;

    public int getMinimumDifference(TreeNode root) {
        inOrder(root);
        return res;
    }

    public void inOrder(TreeNode node) {
        if (node == null) return;
        inOrder(node.left);
        if (prev != null) res = Math.min(res, Math.abs(node.val - prev.val));
        prev = node;
        inOrder(node.right);
    }
}
